﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace WROA.Helper
{
    public class AddCookit
    {
        public void AddCookitToLoginUser(string userName,string roleName)
        {
            FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
            1,
            userName,
            DateTime.Now,
            DateTime.Now.AddMinutes(20),//保存时间
            false,
            roleName//写入用户角色
            );

            string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

            System.Web.HttpCookie authCookie = new System.Web.HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
            System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
        }
    }
}